package cn._2dland.leech.download;

import java.io.IOException;

import cn._2dland.leech.IDownloader;
import cn._2dland.util.Logger;

public class IDMDownloader implements IDownloader {
	private static final String IDM_PATH = "D:\\Program Files (x86)\\Internet Download Manager\\IDMan.exe";

	public void save(String url, String referer, String savePath) {
		// 构造下载命令行
		StringBuffer buf = new StringBuffer();
		buf.append("\"").append(IDM_PATH).append("\" /n ")
			.append("/d \"").append(url).append("\" ")
			.append("/p ").append(savePath);

		// 通过命令行调用IDM下载
		try {
			Runtime rt = Runtime.getRuntime();
			rt.exec(buf.toString());
		} catch (IOException e) {
			e.printStackTrace();
		}

		Logger.debug(url + " 已添加到IDM下载任务中!");
	}
}
